package com.net.wanjian.networkhospitalmanager.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.bean.teacherevent.DepartmentListResult;
import com.net.wanjian.networkhospitalmanager.utils.URLDecoderUtil;

import java.util.List;

/**
 * Description:
 * Created by lidongcai on 17/5/26.
 * Email:  lidongcaiocc@163.com
 */

public class SecondListDepartmentAdapter extends BaseAdapter {
    private Context context;
    private List<DepartmentListResult.DataBean.DepartmentListBean.SecondDepartmentListBean> list;
    //            选中二级联动的时候记录一级联动的位置
    private int mFirstPosition = 0;
    //        一级联动 现在被选中的位置
    private int mFirstCurrentPosition;

    public SecondListDepartmentAdapter(Context context, List<DepartmentListResult.DataBean.DepartmentListBean.SecondDepartmentListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_teacher_event_listview_right, parent,false);
            holder.nameTV = (TextView) convertView.findViewById(R.id.item_teacher_event_listview_right_tv);

            holder.tagImageView = (ImageView) convertView.findViewById(R.id.item_teacher_event_listview_right_select_iv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
//              选中和没选中时，设置不同的颜色
      /*  if (position == selectedPosition) {
            holder.nameTV.setTextColor(context.getResources().getColor(R.color.colorMain));

            holder.tagImageView.setVisibility(View.VISIBLE);
        } else {
            holder.nameTV.setTextColor(Color.BLACK);

            holder.tagImageView.setVisibility(View.GONE);
        }*/

//            选中和没选中时,给二级联动的item设置不同的颜色
        if (position == selectedPosition && mFirstPosition == mFirstCurrentPosition) {
            convertView.setBackgroundColor(Color.WHITE);
            holder.nameTV.setTextColor(context.getResources().getColor(R.color.colorMain));
            holder.tagImageView.setVisibility(View.VISIBLE);
        } else {
            convertView.setBackgroundColor(Color.WHITE);
            holder.nameTV.setTextColor(Color.BLACK);
            holder.tagImageView.setVisibility(View.GONE);
        }
        holder.nameTV.setText(URLDecoderUtil.getDecoder(list.get(position).getDepartmentName()));
        return convertView;
    }

    private int selectedPosition = 0;

    public void setSelectedPosition(int selectedPosition) {
        this.selectedPosition = selectedPosition;
    }

    public int getSelectedPosition() {
        return selectedPosition;
    }

    public void setFirstPosition(int firstPosition) {
        mFirstPosition = firstPosition;
    }

    public void setFirstCurrentPosition(int firstCurrentPosition) {
        mFirstCurrentPosition = firstCurrentPosition;
    }

    private class ViewHolder {
        TextView nameTV;
        ImageView tagImageView;
    }

}
